import request from '@/utils/request'
import Qs from 'qs'

export function login (data) {
  return request({
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
    },
    transformRequest: [function (data) { // 在请求之前对data传参进行格式转换
      data = Qs.stringify(data)
      return data
    }],
    url: '/user/login',
    method: 'post',
    data: {
      account: data.username,
      password: data.password
    }
  })
}

export function getInfo (token) {
  return request({
    url: '/user/info',
    method: 'get',
    params: { token }
  })
}

export function logout () {
  return request({
    url: '/user/logout',
    method: 'post'
  })
}

export function queryUserList (query) {
  return request({
    url: '/user/queryUserList',
    method: 'get',
    params: query
  })
}

export function addUser (data) {
  console.log(typeof data)
  return request({
    url: '/user/addUser',
    method: 'post',
    data: data
  })
}

export function updateUser (data) {
  console.log(typeof data)
  return request({
    url: '/user/updateUser',
    method: 'post',
    data: data
  })
}
